# Copyright 2010, Scott W. Dunlop <swdunlop@gmail.com>, All Rights Reserved.

include Makefile.cf

# Derive Compiler Configuration from NX_*
CC ?= $(NX_CC)
CFLAGS += $(NX_CFLAGS)
LIBS   += $(NX_LIBS)

# Structure of NoSpex Dependencies
NOSPEX_OBJECTS = util$(O) data$(O) render$(O) physics$(O) widget$(O)

NOSPEX = nospex$(EXE)
LIBNOSPEX = libnospex$(SO)

# A little plumbing to permit running python examples in-situ.
PYTHON=PYTHONPATH=python LD_LIBRARY_PATH=nospex python2.6
PYGDB=PYTHONPATH=python LD_LIBRARY_PATH=nospex gdb --args python2.6
PYDBG=PYTHONPATH=python LD_LIBRARY_PATH=nospex winpdb

# Used by packaging targets.
DATE = $(shell date +%Y%m%d)

compile::
	cd nospex && make compile
	cd python && make compile

run::
	cd nospex && make run

install::
	cd nospex && make install 
	cd python && make install 
	install -m 0755 examples/twitmap.py $(INSTALL_BIN)/twitmap
	install -m 0755 examples/ldmap.py $(INSTALL_BIN)/ldmap

debug::
	cd nospex && make debug

clean::
	cd nospex && make clean
	cd python && make clean

distclean:: 
	cd nospex && make distclean
	cd python && make distclean

lfthud:: run-lfthud

demo1:: run-demo1

repl:: compile
	$(PYTHON)

test:: test_nospex

test_nospex:: compile
	$(PYTHON) test/test_nospex.py

$(LIBNOSPEX): $(NOSPEX_OBJECTS)
	$(LD) -shared $(LIBS) $(NOSPEX_OBJECTS) -o $@

$(NOSPEX): $(LIBNOSPEX) main$(O)
	$(CC) $(CFLAGS) $(LIBS) $(LIBNOSPEX) main$(O) -o $@

%.o: %.c *.h
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

run-%:: examples/%.py compile 
	$(PYTHON) $<

gdb-%:: examples/%.py compile 
	$(PYGDB) $<

dbg-%:: examples/%.py compile 
	$(PYDBG) $<

srcpkg:: 
	rm -rf nospex-$(DATE)
	mkdir nospex-$(DATE)
	
	cp Makefile Makefile.cf README CHANGES LICENSE nospex-$(DATE)
	mkdir nospex-$(DATE)/nospex
	cp nospex/*.[ch] nospex/Makefile nospex-$(DATE)/nospex
	mkdir nospex-$(DATE)/python
	cp python/*.py python/*.[ch] python/Makefile nospex-$(DATE)/python
	mkdir nospex-$(DATE)/examples
	cp examples/*.py Makefile nospex-$(DATE)/examples
	tar -czpvf nospex-$(DATE).tgz nospex-$(DATE)	
	rm -rf nospex-$(DATE)
